// 导入 Vue 框架。
import Vue from "vue";

// 导入 VueRouter 路由框架。
import VueRouter from "vue-router";

Vue.use(VueRouter);

// 定义路由。
const routes = [
    {
        path: "/",
        component: () => import(/* webpackChunkName: "home-layout" */ "../layouts/home-layout.vue"),
        redirect: "/home",
        children: [
            {path: "/home", redirect: "/home/chat"},
            {
                path: "/home/chat",
                component: () => import(/* webpackChunkName: "home-chat-layout" */ "../layouts/home-chat-layout.vue"),
                redirect: "/home/chat/list",
                children: [
                    {path: "/home/chat/list", component: () => import(/* webpackChunkName: "home-chat-list" */ "../views/home/chat/list.vue")},
                    {path: "/home/chat/info/:id", component: () => import(/* webpackChunkName: "home-chat-info" */ "../views/home/chat/info.vue")},
                ]
            },
            {
                path: "/home/contact",
                component: () => import(/* webpackChunkName: "home-chat-layout" */ "../layouts/home-contact-layout.vue"),
                redirect: "/home/contact/list",
                children: [
                    {path: "/home/contact/list", component: () => import(/* webpackChunkName: "home-chat-list" */ "../views/home/contact/list.vue")},
                ]
            },
            {
                path: "/home/collect",
                component: () => import(/* webpackChunkName: "home-chat-layout" */ "../layouts/home-collect-layout.vue"),
                redirect: "/home/collect/list",
                children: [
                    {path: "/home/collect/list", component: () => import(/* webpackChunkName: "home-chat-list" */ "../views/home/collect/list.vue")},
                ]
            }
        ]
    },
    {
        path: "/login",
        component: () => import(/* webpackChunkName: "login-layout" */ "../layouts/login-layout.vue"),
        redirect: "/login/form",
        children: [
            {path: "/login/form", component: () => import(/* webpackChunkName: "login-form" */ "../views/login/form.vue")},
            {path: "/login/setting", component: () => import(/* webpackChunkName: "login-setting" */ "../views/login/setting.vue")},
        ]
    }
];

// 创建路由实例。
const router = new VueRouter({
    mode: "hash",
    base: process.env.BASE_URL,
    routes
});

// 前置守卫。
router.beforeEach((to, from, next) => {
    next();
});

// 导出路由。
export default router;